************************************************************************************************
**** Appendix Figure G4.VARIATION IN MAINLINE SPEED DISTRIBUTION BY HOUR AND DAY-OF-WEEK
************************************************************************************************

set scheme s1mono
* Get reliability
*I 10 W
use ".\data\clean\HV_ML_reliab", clear
keep if fwy==10&dir=="W"
format date %d
sort date hour
tempfile temp2
save `temp2'


use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear

sort date hour
merge m:1 date hour using `temp2', keep(1 3) nogen 
drop if weekend==1
keep if inlist(hour,5,6,7,8)
drop if holiday==1

*WTP calculation
gen EL_TT=dist/ELspeed
gen ML_TT=dist/MLspeed
gen MP=inlist(hour,5,6,7,8)&weekend==0
gen TT_dif_hr=ML_TT-EL_TT
gen WTP2=charged_toll/TT_dif_hr



gen reliabilityML=dist/p20_speedML-dist/p50_speedML
gen reliabilityHV=dist/p20_speedHV-dist/p50_speedHV
gen reliability_diff=reliabilityML-reliabilityHV
replace reliability_diff=0 if reliability_diff<0.01
*keep if WTP2>0&WTP2~=.
keep if reliability_diff~=.
drop if TT_dif_hr==.
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
collapse (mean) MLspeed_mean=MLspeed, by(date hour dow)
keep if inlist(hour,5,6,7,8)
sort date hour
forval dd=1/5{
	forval hh=5/8{
		local plist "`plist' (line MLspeed_mean date if hour==`hh' & dow==`dd')"
	}
}
twoway `plist', legend(off) xsc(r(5 8.7))  plotregion(style(none))
graph export ".\results\appendix\figs\AFG4.png", width(2550) replace
